package no.spk.util.inforama.service.factory.impl;

import no.spk.util.inforama.service.deployable.Deployable;
import no.spk.util.inforama.service.deployable.WebArchive;
import no.spk.util.inforama.service.deployable.impl.DeployableAnalyzerImpl;
import no.spk.util.inforama.service.factory.DeployableFactory;
/**
 * @author Marius
 */
public class DeployableFactoryImpl implements DeployableFactory {

	public Deployable createDeployable(String name, String path, String type) {
		Deployable deployable = null;
		deployable = createArchiveFromType(name, path, type, deployable);
		deployable.setPOM(new DeployableAnalyzerImpl(path).getPOM());
		
		return deployable;
	}

	private Deployable createArchiveFromType(String name, String path,
			String type, Deployable deployable) {
		if(type.equals("war")){
			deployable =  createWebArchive(name, path);
		}
		else{
			throw new RuntimeException("Invalid deployable type!");
		}
		return deployable;
	}
	
	private WebArchive createWebArchive(String name, String path){
		return new WebArchive(name, path);
	}

}
